#include<iostream>
#include <string>
#include <cstdlib>
#include <cstring>
#include <sys/ipc.h>
#include <sys/shm.h>
#include <sys/types.h>
#include <sys/types.h>
#include <sys/stat.h>
using namespace std;


int main()
{
	//1、开辟
	int key = ftok("loveyou", 0x1111);
	int shmid = shmget(key, 4096, IPC_CREAT | 0666);
	cout << "已经开辟内存" << endl;
	//2、链接
	char *ptr = (char*)shmat(shmid, nullptr, 0);	
	cout << "已经链接地址空间" << endl;
	
	//3、断开链接
	shmdt(ptr);
	cout << "已经断开链接" << endl;
	//4、销毁
	shmctl(shmid, IPC_RMID, nullptr);
	cout << "已经销毁共享内存" << endl;

	return 0;
	
}
